package com.iamk.util;

/**
 * <p>Copyright: Copyright (c) 2012</p> <p>Company: Telsoft</p>
 *
 * @version 1.0
 */


import java.util.Enumeration;
import java.util.Properties;
import java.util.ResourceBundle;

public class ResourceBundleUtil {

    private String strBundleFileName = "";

    public ResourceBundleUtil(String bundleFileName) {
        strBundleFileName = bundleFileName;
    }

    public String getObjectAsString(String objectName) {
        return ResourceBundle.getBundle(strBundleFileName).getObject(objectName).toString();
    }

//    public String getAMObjectAsString(String objectName) {
//        return ResourceBundle.getBundle("com.telsoft.resources.bundle.admin." + strBundleFileName, FacesContext.getCurrentInstance().getViewRoot().getLocale()).getObject(objectName).toString();
//    }

    public int getObjectAsIntegerPrimitive(String objectName) {
        return Integer.parseInt(getObjectAsString(objectName));
    }

//    public static String getAMObjectAsString(String bundleFileName, String objectName) {
//        ResourceBundleUtil resource = new ResourceBundleUtil(bundleFileName);
//        return resource.getAMObjectAsString(objectName);
//    }

    public static ResourceBundle getResourceBundle(String strResourceName) {
        return ResourceBundle.getBundle("com.telsoft.resources.bundle.admin." + strResourceName);
    }
    public static ResourceBundle getDefaultResourceBundle(String strResourceName) {
        return ResourceBundle.getBundle(strResourceName);
    }
    public static Properties getpropertiesFile(String strFileName) {
        return convertResourceBundleToProperties(getDefaultResourceBundle(strFileName));
    }

    public static Properties convertResourceBundleToProperties(ResourceBundle resource) {
        Properties properties = new Properties();
        Enumeration<String> keys = resource.getKeys();
        while (keys.hasMoreElements()) {
            String key = keys.nextElement();
            properties.put(key, resource.getString(key));
        }
        return properties;
    }
    // 1. other methods, for example: getObjectAsDate()
}
